package com.zwps.biz.domain.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zwps.biz.api.model.vo.reservoirwaterlevel.ReservoirWaterLevelVO;
import com.zwps.biz.dal.db.dao.ReservoirWaterLevelDAO;
import com.zwps.biz.dal.db.object.ReservoirWaterLevelDO;
import com.zwps.biz.domain.converter.ReservoirWaterLevelConverter;
import com.zwps.biz.domain.service.ReservoirWaterLevelService;
import com.zwps.common.core.exception.UserActionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Administrator
 */
@Service
public class ReservoirWaterLevelServiceImpl  extends ServiceImpl<ReservoirWaterLevelDAO, ReservoirWaterLevelDO> implements ReservoirWaterLevelService {
    @Autowired
    private ReservoirWaterLevelDAO reservoirWaterLevelDAO;
    @Override
    public List<ReservoirWaterLevelVO> getReservoirWaterLevel(String rscd) {
        QueryWrapper<ReservoirWaterLevelDO> wrapper = new QueryWrapper<>();
        wrapper.select("WATER_LEVEL","area_km2","CBCM").eq("RSCD",rscd);
        List<ReservoirWaterLevelDO> levelDOS = reservoirWaterLevelDAO.selectList(wrapper);
        if (null==levelDOS){
            throw new UserActionException("水库编号错误");
        }
        ArrayList<ReservoirWaterLevelVO> list = new ArrayList<>();
        if (CollectionUtil.isNotEmpty(levelDOS)) {
            for (ReservoirWaterLevelDO waterLevelDO : levelDOS) {
                ReservoirWaterLevelVO waterLevelVO = ReservoirWaterLevelConverter.INSTANCE.ReservoirWaterLevelVO(waterLevelDO);
                list.add(waterLevelVO);
            }
        }
        return list;

    }
}
